package banking.domain;

public class CheckingAccount extends Account {
		private double overdraftProtection;
		CheckingAccount(double balance){
			super(balance);
		}
		CheckingAccount(double balance,double protect){
				super(balance);
				overdraftProtection=protect;
		}
		public void withdraw (double amt) throws OverdraftException{
				if(amt>balance&&overdraftProtection==0) {
						throw new OverdraftException("No overdraft protection",amt-balance);
				}
				else if(amt>balance&&amt-balance>overdraftProtection) {
					throw new  OverdraftException("Insufficient funds",amt);
				}
				else if(amt>balance&&amt-balance<overdraftProtection) {
					overdraftProtection=overdraftProtection-(amt-balance);
					balance=0;
					}
				else
					balance-=amt;
		}
}
